#include <iostream>
using namespace std;
int vs[1007], wps[1007], dp[1007];
int main()
{
    int n, t, m = 1, x, w, v, k;
    cin >> n >> t;
    for (int i = 1; i <= n; i++){
        cin >> x >> w >> v;
        k = 1;
        while (k <= x){//转化为01背包
            vs[m] = k * v;
            wps[m++] = k * w;
            x -= k;
            k *= 2;
        }if (x > 0){
            vs[m] = x * v;
            wps[m++] = x * w;
        }
    }
    for (int i = 1; i <= m; i++)
        for (int j = t; j >= wps[i]; j--)
            dp[j] = max(dp[j], dp[j - wps[i]] + vs[i]);
    cout << dp[t] << endl;
    return 0;
}